package Unicart.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

public class LoginPage extends AnyPage {

	public LoginPage(PageManager pages) {
		super(pages);
	}

  @FindBy(id = "username")
  private WebElement usernameField;

  @FindBy(id = "password")
  private WebElement passwordField;

  @FindBy(name = "login")
  private WebElement submitButton;
  
  public LoginPage setUsernameField(String text) {
	usernameField.click();
	usernameField.clear();
	usernameField.sendKeys(Keys.HOME);
	usernameField.sendKeys(text);
    return this;
  }

  public LoginPage setPasswordField(String text) {
    passwordField.sendKeys(text);
    return this;
  }

  public LoginPage ensurePageLoaded() {
    super.ensurePageLoaded();
    wait.until(presenceOfElementLocated(By.cssSelector("input#username")));
    return this;
  }
  
  public InternalPage clickSubmitButton() {
	submitButton.click();
	return pages.internalPage;
  }
}
